package net.awpspace.caromini;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Board {
	Image row, col;
	int R = 20, C = 20;
	int x, y;
	int w = 25, h = 25;

	public Board(Image row, Image col, int x, int y) {
		this.row = row;
		this.col = col;
		this.x = x;
		this.y = y;
	}

	public void move(int deltaX, int deltaY) {
		x += deltaX;
		y += deltaY;
		if (x >= 0)
			x = 0;
		if (y >= 0)
			y = 0;
		if (x + 500 <= 240)
			x = 240-500;
		if (y + 500 <= 320)
			y = 320 - 500;
	}

	private void drawBoard(Graphics g) {
		for (int i = 0; i <= R; i++) {
			g.drawImage(row, x, y + w * i, 0);
		}
		for (int i = 0; i <= C; i++) {
			g.drawImage(col, x + h * i, y, 0);
		}
	}

	public void drawValue(Graphics g, int[][] matrix, Image X, Image O) {
		for (int i = 0; i < R; i++)
			for (int j = 0; j < C; j++)
				if (matrix[i][j] == 1) {
					g.drawImage(X, x + i * w, y + j * h, 0);
				} else if (matrix[i][j] == 2) {
					g.drawImage(O, x + i * w, y + j * h, 0);
				}
	}

	public void paint(Graphics g) {
		drawBoard(g);
	}
}
